Welcome to python!

2.05 字符串拼接

我们经常需要使用将多个字符串拼接到一起,组合成一个大的字符串,这种拼接有多种方法,有以下两种方法:

1、 使用+号拼接

s1="张三"

s2="李四"

print(s1+s2)

返回值:

张三李四

2、 使用拼接函数

s1="张三"

s2="李四"

s3="hello,{}{}".format(s1,s2) #{}是一个占位符,先用一个占位符占着,后面跟一个函数名,有多少个占们符,后面就跟多少个变量

print(s3)

返回值:

hello,张三李四